<!-- 
/**
 * Copyright (c) 2024-2024, Kevin Yang 杨云超 (yyc1030@qq.com).
 *
 * CJFinal is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *      http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 *
 *      Mulan Permissive Software License，Version 2
 *
 * Mulan Permissive Software License，Version 2 (Mulan PSL v2)
 * January 2020 http://license.coscl.org.cn/MulanPSL2
 */ 
-->
<!DOCTYPE html>
<html>
    <head><title>WebSocket测试</title></head>
    <body>
        <button onclick="onClick()">连接</button>
        <button onclick="onClose()">关闭</button> <br/>
        <button onclick="onSendHello()">发送“Hello”</button>
        <button onclick="onSendPing()">Ping</button>
        <button onclick="onSendPong()">Pong</button>
        <div id="info"></div>
        <script type="text/javascript">
            let socket
            function onClick(){

                socket = new WebSocket("ws://127.0.0.1:8080/ws")
                socket.binaryType = 'arraybuffer'

                socket.onopen = function(event){
                    console.log("已连接。。。")
                }

                socket.onmessage = function(event){
                    document.getElementById("info").innerText = event.data
                    console.log(event)
                }

                socket.onerror = function(error){
                    console.log(error)
                }

                socket.onclose = function(event){
                    console.log("连接已关闭！")
                }
            }

            function onSendHello(){
                socket.send("Hello")
            }

            function onClose(){
                socket.close()
            }

            function onSendPing(){
                socket.send("Ping");
            }

            function onSendPong(){
                socket.send("pong")
            }
        </script>
    </body>
</html>